package leetcode;

import java.util.*;

public class LC554 {

    public static int leastBricks(List<List<Integer>> wall) {
        HashMap<Integer,Integer> map = new HashMap<Integer, Integer>(){{
            put(1,2);
        }};


        for (List<Integer> list : wall) {
            int sum = 0;
            for (int i = 0; i < list.size() - 1; i++) {
                sum += list.get(i);
                int cnt = map.getOrDefault(sum,0);
                map.put(sum,cnt + 1);
            }
        }
        int maxSum = 0;
        for (HashMap.Entry<Integer,Integer> entry : map.entrySet()) {
            maxSum = Math.max(maxSum,entry.getValue());
        }
        return wall.size() - maxSum;
    }

    public static void main(String[] args) {
        List<List<Integer>> list = new ArrayList<>();
        leastBricks(list);


    }

}
